Passive Infrared (PIR) Motion Sensor

This week we were supposed to add a sensor to a microcontroller board that we designed and read the input in some way. I started off milling Neil's board for the pyroelectric motion sensor.

Neil's Board Neil's Board Components Neil's Board Stuffed

I did not want to have to desolder and resolder the PIR motion sensor to different boards, so I decided to use a 3-pin FTDI header and connect the board to the motion sensor with three jumper cables:

Connecting to Sensor with Jumper Cables

Then I saved Neil's .c and .make files to a local directory and programmed the board. After saving Neil's .py file in the same directory, I used the following command to bring up the python window in the terminal on a macbook. The python window was used to indicate whether the input device could sense a motion or not:

Note that the last bit of this command requires the name of the serial port. Rob showed me how to use CoolTerm to obtain this name. Here is a screenshot of CoolTerm. Under "Options", click on "Serial Port" on the left, then hit "Re-Scan Serial Ports" in order for CoolTerm to detect the serial port. Under "port" there should be one starting with "usbserial-":

CoolTerm and Python Command

The motion sensor was able to detect motions and send the input back through the serial port. We could also use the "Connect" function in CoolTerm to read the input signals. I used Neil's python code. In the python window the color changed from blue to red whenever there was a motion near the motion sensor. So I was able to successfully replicate Neil's example:



Then I went on to create my own version of the board. Instead of using a python window to measure input, I wanted to use an LED which would turn on if the motion sensor detected motion and turn off when no motion was detected. I tried to look for the "pyroelectric" or the passive infrared component in Eagle's libraries, but I couldn't find it. I did some search online and found a fab.lbr file from a past-year student's webpage. The problem though was that this component had a different shape. I have decided to include it here just in case it could be helpful to others in the future.

Library with PIR
PIR Motion Sensor Component

In order to design my own board in Eagle, I ended up using a component named "SPDTSwitch", which looked like a 3-pin FTDI header:

Proxy for PIR Motion Sensor Component

Here are the files and pictures of my schematic and board views:

My Board Schematic
My Board All My Board Traces My Board Border

I then tried to mill my board. For some reason, some of the edges came out a bit rough and I had to deburr the board lightly with sand paper. (In class Neil mentioned that this could be because the endmill was either too "new" and too sharp or too old and too destroyed.) I then connected the board to the motion sensor through the same jumper cables.

My Board Milled My Board Components My Board Stuffed My Board Connected to Sensor

I asked Albert and Rob for some help with the modification of Neil's original C code to take into account the LED. Rob explained to me which new variables I would need to define and how to modify the main function to light up the LED when motion was detected:

Modifying Neil's Code 1 Modifying Neil's Code 2

Here is the new .c file: Ye.hello.HC-SR501.c; and here are some pictures and a video to show the motion sensor and LED in motion:

Motion Sensor and LED 1 Motion Sensor and LED 2

This is essentially the same as the bathroom light turning on when someone walks in, although I would certainly need more lights to light up the entire room.


I wanted to thank Rob and Albert for their help this week! Rob is amazing!!